#include <iostream>
#include <list>

using namespace std;

int get_animals(list<int>* animals, int animal_type);

int main()
{
    int first, second, result;
    list<int> animals, results;
    while (cin >> first) {
        cin >> second;
        if (first == 1 && second != 0)
        {
            animals.push_back(second);
        }
        else if (first == 2) {
            if (second == 0) {
                results.push_back(animals.front());
                animals.pop_front();
            }
            else if (abs(second) == 1) {
                result = get_animals(&animals, second);
                if (result != 0) {
                    results.push_back(result);
                }
            }
        }
    }
    list<int>::iterator result_iter = results.begin();
    while (result_iter != results.end()) {
        cout << *result_iter;
        ++result_iter;
        if (result_iter != results.end()) {
            cout << " ";
        }
    }
}

int get_animals(list<int>* animals, int animal_type)
{
    int result = 0;
    list<int>::iterator animal_iter = (*animals).begin();
    for (; animal_iter != (*animals).end(); ++animal_iter) {
        if (animal_type * (*animal_iter) > 0) {
            result = (*animal_iter);
            (*animals).erase(animal_iter);
            break;
        }
    }
    return result;
}
